import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SolutionInterview17_18 {
    public int[] shortestSeq(int[] big, int[] small) {
        Map<Integer,Integer> m1=new HashMap<>();
        for (int i : small) {
            m1.put(i,m1.getOrDefault(i,0)+1);
        }
        Map<Integer,Integer> m2=new HashMap<>();
        for (Map.Entry<Integer, Integer> entry : m1.entrySet()) {
            m2.put(entry.getKey(),0);
        }
        int res=m1.size(),r=-1;
        for (int i=0;i<big.length;i++){
            if (m1.containsKey(big[i])){
                m2.put(big[i],m2.get(big[i])+1);
                if (m2.get(big[i]).equals(m1.get(big[i]))){
                    res--;
                    if (res==0){
                        r=i;
                        break;
                    }
                }
            }
        }
        if (r==-1){
            return new int[]{};
        }
        int min=r+1,ansL=0,ansR=r;
        for (int l=0;l<big.length && r<big.length;){
            if (m1.containsKey(big[l]) && m2.get(big[l]).equals(m1.get(big[l]))){
                r++;
                while (r<big.length && big[r]!=big[l]){
                    m2.put(big[r],m2.getOrDefault(big[r],0)+1);
                    r++;
                }
                if (r==big.length){
                    continue;
                }
                m2.put(big[r],m2.get(big[r])+1);
            }
            m2.put(big[l],m2.getOrDefault(big[l],0)-1);
            l++;
            if (r-l+1<min){
                min=r-l+1;
                ansL=l;
                ansR=r;
            }
        }
        return new int[]{ansL,ansR};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionInterview17_18().shortestSeq(new int[]{7, 5, 9, 0, 2, 1, 3, 5, 7, 9, 1, 1, 5, 8, 8, 9, 7}, new int[]{1, 5, 9})));
    }
}
